home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Shout3Ddemo / Shout3d_runtime / codebase / applets / ExamineWithButtonsApplet.java < prev    next >
Text File  |  2000-11-03  |  4KB  |  131 lines

  1. /**    
  2.     Company:        Eyematic Interfaces
  3.     Project:        Shout3D 2.0 Sample Code
  4.     Class:            ExaminePanel with buttons to control it.
  5.     Date:            Nov 1, 2000
  6.     Description:    Class for ExaminePanel
  7.     (C) Copyright Eyematic Interfaces, Inc. - 1997-2000 - All rights reserved
  8.  */
  9.  
  10.  
  11.  
  12. package applets;
  13.  
  14. import java.awt.*;
  15. import shout3d.*;
  16.  
  17. /**
  18.  * A simple panel class that shows how to lay out buttons with a Shout3DPanel.
  19.  * Puts up buttons to control the behavior of an ExaminePanel.
  20.  */
  21.  
  22. public class ExamineWithButtonsApplet extends Shout3DApplet {
  23.     
  24.     // Buttons to select drag style:
  25.     Label     dragStyleLabel;
  26.     Checkbox bySpeedCheckbox;
  27.     Checkbox byOffsetCheckbox;
  28.     
  29.     // Buttons to change the center of rotation
  30.     Label  centerSelectLabel;
  31.     Button upButton;    
  32.     Button downButton;        
  33.     Button leftButton;    
  34.     Button rightButton;    
  35.     
  36.     int BUTTON_HEIGHT = 25;
  37.  
  38.     // Reference to the panel.
  39.     ExaminePanel myExaminePanel;
  40.     
  41.     /**
  42.      * Very important: 
  43.      * Add buttons during initShout3DPanel, not during init().
  44.      */
  45.     public void initShout3DPanel(){
  46.         int width = size().width;
  47.         int height = size().height;
  48.         int panelHeight = height - 2 * BUTTON_HEIGHT;
  49.         int panelWidth = width;
  50.         int buttonWidth = width/5;
  51.         
  52.         panel = new ExaminePanel(this, panelWidth, panelHeight);
  53.         myExaminePanel = (ExaminePanel) panel;
  54.                 
  55.         dragStyleLabel = new Label("Drag Style:");
  56.         bySpeedCheckbox  = new Checkbox("By Speed", true);
  57.         byOffsetCheckbox = new Checkbox("By Offset", false);
  58.         dragStyleLabel.reshape(0, panelHeight, buttonWidth, BUTTON_HEIGHT);
  59.         bySpeedCheckbox.reshape( buttonWidth,   panelHeight, buttonWidth, BUTTON_HEIGHT);
  60.         byOffsetCheckbox.reshape(2*buttonWidth, panelHeight, buttonWidth, BUTTON_HEIGHT);
  61.         add(dragStyleLabel);
  62.         add(bySpeedCheckbox);
  63.         add(byOffsetCheckbox);
  64.  
  65.         centerSelectLabel = new Label("Move Center:");
  66.         upButton    = new Button("Up");
  67.         downButton  = new Button("Down");
  68.         leftButton  = new Button("Left");
  69.         rightButton = new Button("Right");
  70.         centerSelectLabel.reshape(0, panelHeight+BUTTON_HEIGHT,     buttonWidth, BUTTON_HEIGHT);
  71.         upButton.reshape(      buttonWidth,   panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
  72.         downButton.reshape(  2*buttonWidth,   panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
  73.         leftButton.reshape(  3*buttonWidth,   panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
  74.         rightButton.reshape( 4*buttonWidth,   panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
  75.         add(centerSelectLabel);
  76.         add(upButton);
  77.         add(downButton);
  78.         add(leftButton);
  79.         add(rightButton);
  80.     }    
  81.     
  82.     public boolean action(Event e, Object o) {
  83.         if (e.target instanceof Checkbox) {
  84.             // Select a dragStyle.
  85.             Checkbox c = (Checkbox) e.target;
  86.             boolean isBySpeed = true;
  87.             if (c == bySpeedCheckbox){
  88.                 isBySpeed = bySpeedCheckbox.getState();
  89.                 byOffsetCheckbox.setState(!isBySpeed);
  90.             }
  91.             else if (c == byOffsetCheckbox){
  92.                 isBySpeed = !byOffsetCheckbox.getState();
  93.                 bySpeedCheckbox.setState(isBySpeed);
  94.             }
  95.             myExaminePanel.currentDragStyle = (isBySpeed) ? ExaminePanel.BY_SPEED : 
  96.                                                             ExaminePanel.BY_OFFSET;
  97.         }
  98.         if (e.target instanceof Button) {
  99.             if (e.target == upButton) {
  100.                 myExaminePanel.rotationCenter    = myExaminePanel.bboxCenter;
  101.                 myExaminePanel.rotationCenter[1] = myExaminePanel.rotationCenter[1]+1;
  102.                 myExaminePanel.resetCamera();
  103.                 return true;
  104.             }    
  105.             if (e.target == leftButton) {
  106.                 myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
  107.                 myExaminePanel.rotationCenter[0] = myExaminePanel.rotationCenter[0]-1;
  108.                 myExaminePanel.resetCamera();
  109.                 return true;
  110.             }
  111.             if (e.target == rightButton) {
  112.                 myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
  113.                 myExaminePanel.rotationCenter[0] = myExaminePanel.rotationCenter[0]+1;
  114.                 myExaminePanel.resetCamera();
  115.                 return true;
  116.             }
  117.             if (e.target == downButton) {
  118.                 myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
  119.                 myExaminePanel.rotationCenter[1] = myExaminePanel.rotationCenter[1]-1;
  120.                 myExaminePanel.resetCamera();
  121.                 return true;
  122.             }
  123.             return false;      
  124.         }
  125.  
  126.         //not a button event
  127.         return false; 
  128.  
  129.     }//end of action method
  130. }
  131.